package cn.com.tiza.spiro.jvm.gc.optimization;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by TZ0643 on 2016-1-5.
 * 将新对象留在新生代直到到达晋升年龄
 */
public class StayInYoungGenCase {

    public static final byte[] _10M = new byte[1024 * 1024 * 10];

    static class StayIn {
        private byte[] _1M = new byte[1024 * 1024];
    }

    public static List list = new ArrayList();
    public static void main(String[] args) {

        while(true) {
            if(list.size() > 20) {
                list.clear();
            }

            StayIn stayIn = new StayIn();
            list.add(stayIn);
            try {
                Thread.sleep(500);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }
}
